﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Xml;

namespace Little.Soldier.Licensing
{
    internal class EncryptionProvider : LicenseProvider
    {
        private static byte[] SecretKey = new byte[8]
        {
            (byte) 146,
            (byte) 21,
            (byte) 56,
            (byte) 161,
            (byte) 18,
            (byte) 237,
            (byte) 179,
            (byte) 194
        };

        private static byte[] SecretIV = new byte[8]
        {
            (byte) 173,
            (byte) 63,
            (byte) 198,
            (byte) 17,
            (byte) 71,
            (byte) 144,
            (byte) 221,
            (byte) 161
        };

        private const int MaxSize = 7;
        private static string _RSAKeyValue;
        private static byte[] _DesignSignature;
        private static byte[] _RuntimeSignature;

        static EncryptionProvider()
        {
        }

        internal static void InitLicenseParameters(string licenseParameters)
        {
            XmlReader xmlReader = (XmlReader) new XmlTextReader(licenseParameters, XmlNodeType.Element, (XmlParserContext) null);
            while (xmlReader.Read())
            {
                if (xmlReader.IsStartElement())
                {
                    if (xmlReader.LocalName == "RSAKeyValue")
                        EncryptionProvider._RSAKeyValue = xmlReader.ReadOuterXml();
                    if (xmlReader.LocalName == "DesignSignature")
                        EncryptionProvider._DesignSignature = Convert.FromBase64String(xmlReader.ReadElementString());
                    if (xmlReader.LocalName == "RuntimeSignature")
                        EncryptionProvider._RuntimeSignature = Convert.FromBase64String(xmlReader.ReadElementString());
                }
            }
            xmlReader.Close();
        }

        public virtual LicenseInfo GetLicenseInfo(string licenseKey)
        {
            LicenseInfo obj = this.GetLicenseInfo(LicenseManager.CurrentContext, licenseKey);
            if (obj != null)
            {
                StreamWriter streamWriter = new StreamWriter((Stream)new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\" + LicensedFile.GetFileName(), FileMode.Create, FileAccess.Write, FileShare.None));
                streamWriter.WriteLine(licenseKey);
                streamWriter.Close();
            }
            return obj;
        }

        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            string licenseKey = this.GetLicenseInfo(context, type);
            License license = (License)this.GetLicenseInfo(context, type, licenseKey);
            if (license == null && allowExceptions)
                throw new LicenseException(type, instance);
            else
                return license;
        }

        public string Encode(string licenseKey)
        {
            if (EncryptionProvider._RSAKeyValue == null || EncryptionProvider._DesignSignature == null || EncryptionProvider._RuntimeSignature == null)
                return (string) null;
            
            switch (licenseKey)
            {
                case null:
                    return (string) null;
                default:
                    try
                    {
                        #region CryptoServiceProvider
                        byte[] inputBuffer1 = EncryptionProvider.HexToByteArray(licenseKey);
                        DESCryptoServiceProvider cryptoServiceProvider1 = new DESCryptoServiceProvider();
                        cryptoServiceProvider1.Key = EncryptionProvider.SecretKey;
                        cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                        byte[] numArray1 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer1, 0, inputBuffer1.Length);
                        byte[] numArray2 = new byte[EncryptionProvider.KeySize(8)];
                        byte[] inputBuffer2 = new byte[EncryptionProvider.KeySize(numArray1.Length - 7)];
                        Array.Copy((Array) numArray1, 0, (Array) numArray2, 0, 7);
                        Array.Copy((Array) numArray1, 7, (Array) inputBuffer2, 0, inputBuffer2.Length);
                        RSACryptoServiceProvider cryptoServiceProvider2;
                        #endregion

                        if (!Environment.UserInteractive)
                        {
                            #region Not UserInteractive
                            cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                            {
                                Flags = CspProviderFlags.UseMachineKeyStore
                            });
                            #endregion
                        }
                        else
                        {
                            #region UserInteractive
                            try
                            {
                                cryptoServiceProvider2 = new RSACryptoServiceProvider();
                            }
                            catch
                            {
                                try
                                {
                                    cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                                    {
                                        Flags = CspProviderFlags.UseMachineKeyStore
                                    });
                                }
                                catch
                                {
                                    return string.Empty;
                                }
                            }
                            #endregion
                        }

                        cryptoServiceProvider2.FromXmlString(EncryptionProvider._RSAKeyValue);
                        if (!cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._RuntimeSignature) && !cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._DesignSignature))
                            return string.Empty;

                        #region CryptoServiceProvider
                        cryptoServiceProvider1.IV = numArray2;
                        byte[] inputBuffer3 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer2, 0, inputBuffer2.Length);
                        byte[] numArray3 = new byte[EncryptionProvider.KeySize(inputBuffer3.Length - 2)];
                        Array.Copy((Array) inputBuffer3, 2, (Array) numArray3, 0, numArray3.Length);
                        byte[] numArray4 = cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(numArray2, 0, numArray2.Length);
                        byte[] numArray5 = new byte[EncryptionProvider.KeySize(8)];
                        Array.Copy((Array) numArray4, 0, (Array) numArray5, 0, 7);
                        cryptoServiceProvider1.IV = numArray5;
                        byte[] numArray6 = cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(inputBuffer3, 0, inputBuffer3.Length);
                        byte[] inputBuffer4 = new byte[EncryptionProvider.KeySize(7 + numArray6.Length)];
                        numArray5.CopyTo((Array) inputBuffer4, 0);
                        numArray6.CopyTo((Array) inputBuffer4, 7);
                        cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                        #endregion

                        return EncryptionProvider.ByteArrayToString(cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(inputBuffer4, 0, inputBuffer4.Length));
                    }
                    catch
                    {
                        return string.Empty;
                    }
            }
        }

        internal LicenseInfo GetLicenseInfo(string licenseKey, string password)
        {
            try
            {
                byte[] inputBuffer1 = EncryptionProvider.HexToByteArray(licenseKey);
                byte[] a2_1 = new byte[8]
                {
                    (byte) 111,
                    (byte) 166,
                    (byte) 132,
                    (byte) 62,
                    (byte) 196,
                    (byte) 214,
                    (byte) 189,
                    (byte) 29
                };
                if (!EncryptionProvider.VerifyAssembly(Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken(), a2_1))
                    EncryptionProvider.SecretKey.CopyTo((Array)a2_1, 0);
                
                DESCryptoServiceProvider cryptoServiceProvider = new DESCryptoServiceProvider();
                cryptoServiceProvider.Key = EncryptionProvider.SecretKey;
                cryptoServiceProvider.IV = EncryptionProvider.SecretIV;
                byte[] numArray1 = cryptoServiceProvider.CreateDecryptor().TransformFinalBlock(inputBuffer1, 0, inputBuffer1.Length);
                byte[] a1 = new byte[EncryptionProvider.KeySize(8)];
                byte[] inputBuffer2 = new byte[EncryptionProvider.KeySize(numArray1.Length - 7)];
                Array.Copy((Array) numArray1, 0, (Array) a1, 0, 7);
                Array.Copy((Array) numArray1, 7, (Array) inputBuffer2, 0, inputBuffer2.Length);
                byte[] a2_2 = EncryptionProvider.GetBytesPassword(password);
                
                if (!EncryptionProvider.VerifyAssembly(a1, a2_2))
                    return (LicenseInfo) null;
                
                cryptoServiceProvider.IV = a1;
                byte[] numArray2 = cryptoServiceProvider.CreateDecryptor().TransformFinalBlock(inputBuffer2, 0, inputBuffer2.Length);
                byte[] bytes = new byte[EncryptionProvider.KeySize(numArray2.Length - 2)];
                Array.Copy((Array) numArray2, 2, (Array) bytes, 0, bytes.Length);
                ushort serialNo = BitConverter.ToUInt16(numArray2, 0);
                string @string = Encoding.ASCII.GetString(bytes);
                return new LicenseInfo(licenseKey, serialNo, @string);
            }
            catch
            {
                return (LicenseInfo)null;
            }
        }

        private static int KeySize(int length)
        {
          return length;
        }

        private static string RemoveCharacters(string value, string characters)
        {
            switch (value)
            {
                case null:
                    return (string) null;
                default:
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (char ch in value)
                    {
                        if (characters.IndexOf(ch, 0) < 0)
                            stringBuilder.Append(ch);
                    }
                    return ((object) stringBuilder).ToString();
            }
        }

        private static string ByteArrayToString(byte[] data)
        {
            StringBuilder stringBuilder = new StringBuilder();
            for (int index = 0; index < data.Length; ++index)
            {
                if (index > 0 && index % 2 == 0)
                    stringBuilder.Append("-");
                stringBuilder.Append(data[index].ToString("X2"));
            }
            return ((object) stringBuilder).ToString();
        }

        private static byte[] HexToByteArray(string hex)
        {
            string str = EncryptionProvider.RemoveCharacters(hex, "\t\r\n -");
            if (str == null || str.Length % 2 != 0)
                throw new FormatException("Invalid hexadecimal string");
            
            byte[] numArray = new byte[EncryptionProvider.KeySize(str.Length / 2)];
            int startIndex = 0;
            int index = 0;
            while (startIndex < str.Length)
            {
                string s = str.Substring(startIndex, 2);
                numArray[index] = byte.Parse(s, NumberStyles.HexNumber);
                startIndex += 2;
                ++index;
            }
            return numArray;
        }

        internal static bool VerifyAssembly(byte[] a1, byte[] a2)
        {
            if (a1 == a2)
                return true;
            if (a1 == null || (a2 == null || a1.Length != a2.Length))
                return false;
            for (int index = 0; index < a1.Length; ++index)
            {
                if ((int) a1[index] != (int) a2[index])
                    return false;
            }
            return true;
        }

        private static byte[] GetBytesPassword(string password)
        {
            byte[] numArray1 = new byte[8]
            {
                (byte) 242,
                (byte) 161,
                (byte) 3,
                (byte) 157,
                (byte) 99,
                (byte) 135,
                (byte) 53,
                (byte) 94
            };
            byte[] numArray2 = new byte[8]
            {
                (byte) 171,
                (byte) 184,
                (byte) 148,
                (byte) 126,
                (byte) 29,
                (byte) 229,
                (byte) 209,
                (byte) 51
            };
            
            DESCryptoServiceProvider cryptoServiceProvider = new DESCryptoServiceProvider();
            cryptoServiceProvider.Key = numArray1;
            cryptoServiceProvider.IV = numArray2;
            
            if (password.Length < 8)
                password = password.PadRight(8, '*');
            
            byte[] bytes = Encoding.ASCII.GetBytes(password);
            byte[] numArray3 = cryptoServiceProvider.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
            byte[] numArray4 = new byte[EncryptionProvider.KeySize(8)];
            Array.Copy((Array) numArray3, 0, (Array) numArray4, 0, 7);
                        
            return numArray4;
        }

        private LicenseInfo GetLicenseInfo(LicenseContext context, string licenseKey)
        {
            LicensingManager.InitLicenseParameters();
            if (EncryptionProvider._RSAKeyValue == null || EncryptionProvider._DesignSignature == null || EncryptionProvider._RuntimeSignature == null)
            return (LicenseInfo) null;
            switch (licenseKey)
            {
            case null:
                return (LicenseInfo) null;
            default:
                try
                {
                byte[] inputBuffer1 = EncryptionProvider.HexToByteArray(licenseKey);
                DESCryptoServiceProvider cryptoServiceProvider1 = new DESCryptoServiceProvider();
                cryptoServiceProvider1.Key = EncryptionProvider.SecretKey;
                cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                byte[] numArray1 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer1, 0, inputBuffer1.Length);
                byte[] numArray2 = new byte[EncryptionProvider.KeySize(8)];
                byte[] inputBuffer2 = new byte[EncryptionProvider.KeySize(numArray1.Length - 7)];
                Array.Copy((Array) numArray1, 0, (Array) numArray2, 0, 7);
                Array.Copy((Array) numArray1, 7, (Array) inputBuffer2, 0, inputBuffer2.Length);
                RSACryptoServiceProvider cryptoServiceProvider2;
                if (!Environment.UserInteractive)
                {
                    cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                    {
                    Flags = CspProviderFlags.UseMachineKeyStore
                    });
                }
                else
                {
                    try
                    {
                    cryptoServiceProvider2 = new RSACryptoServiceProvider();
                    }
                    catch
                    {
                    try
                    {
                        cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                        {
                        Flags = CspProviderFlags.UseMachineKeyStore
                        });
                    }
                    catch
                    {
                        return (LicenseInfo) null;
                    }
                    }
                }
                cryptoServiceProvider2.FromXmlString(EncryptionProvider._RSAKeyValue);
                if (context.UsageMode == LicenseUsageMode.Designtime)
                {
                    if (!cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._DesignSignature))
                    return (LicenseInfo) null;
                }
                else if (!cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._RuntimeSignature) && !cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._DesignSignature))
                    return (LicenseInfo) null;
                cryptoServiceProvider1.IV = numArray2;
                byte[] inputBuffer3 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer2, 0, inputBuffer2.Length);
                byte[] bytes = new byte[EncryptionProvider.KeySize(inputBuffer3.Length - 2)];
                Array.Copy((Array) inputBuffer3, 2, (Array) bytes, 0, bytes.Length);
                ushort serialNo = BitConverter.ToUInt16(inputBuffer3, 0);
                string @string = Encoding.ASCII.GetString(bytes);
                if (@string != "SWF-11-10" && @string != "SWF-11-11" && (@string != "SWF-11-12" && @string != "SWF-11-13"))
                    return (LicenseInfo) null;
                if (context.UsageMode == LicenseUsageMode.Designtime)
                {
                    byte[] numArray3 = cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(numArray2, 0, numArray2.Length);
                    byte[] numArray4 = new byte[EncryptionProvider.KeySize(8)];
                    Array.Copy((Array) numArray3, 0, (Array) numArray4, 0, 7);
                    cryptoServiceProvider1.IV = numArray4;
                    byte[] numArray5 = cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(inputBuffer3, 0, inputBuffer3.Length);
                    byte[] inputBuffer4 = new byte[EncryptionProvider.KeySize(7 + numArray5.Length)];
                    numArray4.CopyTo((Array) inputBuffer4, 0);
                    numArray5.CopyTo((Array) inputBuffer4, 7);
                    cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                    EncryptionProvider.ByteArrayToString(cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(inputBuffer4, 0, inputBuffer4.Length));
                }
                return new LicenseInfo(licenseKey, serialNo, @string);
                }
                catch
                {
                return (LicenseInfo) null;
                }
            }
        }

        private LicenseInfo GetLicenseInfo(LicenseContext context, Type type, string licenseKey)
        {
            if (EncryptionProvider._RSAKeyValue == null || EncryptionProvider._DesignSignature == null || EncryptionProvider._RuntimeSignature == null)
            return (LicenseInfo) null;
            switch (licenseKey)
            {
            case null:
                return (LicenseInfo) null;
            default:
                try
                {
                    byte[] inputBuffer1 = EncryptionProvider.HexToByteArray(licenseKey);
                DESCryptoServiceProvider cryptoServiceProvider1 = new DESCryptoServiceProvider();
                cryptoServiceProvider1.Key = EncryptionProvider.SecretKey;
                cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                byte[] numArray1 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer1, 0, inputBuffer1.Length);
                byte[] numArray2 = new byte[EncryptionProvider.KeySize(8)];
                byte[] inputBuffer2 = new byte[EncryptionProvider.KeySize(numArray1.Length - 7)];
                Array.Copy((Array) numArray1, 0, (Array) numArray2, 0, 7);
                Array.Copy((Array) numArray1, 7, (Array) inputBuffer2, 0, inputBuffer2.Length);
                RSACryptoServiceProvider cryptoServiceProvider2;
                if (!Environment.UserInteractive)
                {
                    cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                    {
                    Flags = CspProviderFlags.UseMachineKeyStore
                    });
                }
                else
                {
                    try
                    {
                    cryptoServiceProvider2 = new RSACryptoServiceProvider();
                    }
                    catch
                    {
                    try
                    {
                        cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                        {
                        Flags = CspProviderFlags.UseMachineKeyStore
                        });
                    }
                    catch
                    {
                        return (LicenseInfo) null;
                    }
                    }
                }
                cryptoServiceProvider2.FromXmlString(EncryptionProvider._RSAKeyValue);
                if (context.UsageMode == LicenseUsageMode.Designtime)
                {
                    if (!cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._DesignSignature))
                    return (LicenseInfo) null;
                }
                else if (!cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._RuntimeSignature) && !cryptoServiceProvider2.VerifyData(numArray2, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._DesignSignature))
                    return (LicenseInfo) null;
                cryptoServiceProvider1.IV = numArray2;
                byte[] inputBuffer3 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer2, 0, inputBuffer2.Length);
                byte[] bytes = new byte[EncryptionProvider.KeySize(inputBuffer3.Length - 2)];
                Array.Copy((Array) inputBuffer3, 2, (Array) bytes, 0, bytes.Length);
                ushort serialNo = BitConverter.ToUInt16(inputBuffer3, 0);
                string @string = Encoding.ASCII.GetString(bytes);
                if (@string != "SWF-11-10" && @string != "SWF-11-11" && (@string != "SWF-11-12" && @string != "SWF-11-13"))
                    return (LicenseInfo) null;
                if (context.UsageMode == LicenseUsageMode.Designtime)
                {
                    byte[] numArray3 = cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(numArray2, 0, numArray2.Length);
                    byte[] numArray4 = new byte[EncryptionProvider.KeySize(8)];
                    Array.Copy((Array) numArray3, 0, (Array) numArray4, 0, 7);
                    cryptoServiceProvider1.IV = numArray4;
                    byte[] numArray5 = cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(inputBuffer3, 0, inputBuffer3.Length);
                    byte[] inputBuffer4 = new byte[EncryptionProvider.KeySize(7 + numArray5.Length)];
                    numArray4.CopyTo((Array) inputBuffer4, 0);
                    numArray5.CopyTo((Array) inputBuffer4, 7);
                    cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                    string key = EncryptionProvider.ByteArrayToString(cryptoServiceProvider1.CreateEncryptor().TransformFinalBlock(inputBuffer4, 0, inputBuffer4.Length));
                    context.SetSavedLicenseKey(type, key);
                }
                return new LicenseInfo(licenseKey, serialNo, @string);
                }
                catch
                {
                return (LicenseInfo) null;
                }
            }
        }

        internal virtual string GetLicenseInfo(LicenseContext context, Type type)
        {
            string str = (string) null;
            if (context.UsageMode == LicenseUsageMode.Runtime)
            str = context.GetSavedLicenseKey(type, (Assembly) null);
            if (str == null && context.UsageMode == LicenseUsageMode.Designtime)
            {
                string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\" + LicensedFile.GetFileName();
                if (File.Exists(path))
                {
                    StreamReader streamReader = new StreamReader((Stream) new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
                    str = streamReader.ReadLine();
                    streamReader.Close();
                }
            }
            return str;
        }

        internal bool GetKey(string key)
        {
            LicensingManager.InitLicenseParameters();
            if (EncryptionProvider._RSAKeyValue != null && EncryptionProvider._DesignSignature != null)
            {
            if (EncryptionProvider._RuntimeSignature != null)
            {
                try
                {
                    byte[] inputBuffer1 = EncryptionProvider.HexToByteArray(key);
                DESCryptoServiceProvider cryptoServiceProvider1 = new DESCryptoServiceProvider();
                cryptoServiceProvider1.Key = EncryptionProvider.SecretKey;
                cryptoServiceProvider1.IV = EncryptionProvider.SecretIV;
                byte[] numArray1 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer1, 0, inputBuffer1.Length);
                byte[] buffer = new byte[EncryptionProvider.KeySize(8)];
                byte[] inputBuffer2 = new byte[EncryptionProvider.KeySize(numArray1.Length - 7)];
                Array.Copy((Array) numArray1, 0, (Array) buffer, 0, 7);
                Array.Copy((Array) numArray1, 7, (Array) inputBuffer2, 0, inputBuffer2.Length);
                RSACryptoServiceProvider cryptoServiceProvider2;
                if (!Environment.UserInteractive)
                {
                    cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                    {
                    Flags = CspProviderFlags.UseMachineKeyStore
                    });
                }
                else
                {
                    try
                    {
                    cryptoServiceProvider2 = new RSACryptoServiceProvider();
                    }
                    catch
                    {
                    try
                    {
                        cryptoServiceProvider2 = new RSACryptoServiceProvider(new CspParameters()
                        {
                        Flags = CspProviderFlags.UseMachineKeyStore
                        });
                    }
                    catch
                    {
                        return false;
                    }
                    }
                }
                cryptoServiceProvider2.FromXmlString(EncryptionProvider._RSAKeyValue);
                if (!cryptoServiceProvider2.VerifyData(buffer, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._RuntimeSignature) && !cryptoServiceProvider2.VerifyData(buffer, (object) new SHA1CryptoServiceProvider(), EncryptionProvider._DesignSignature))
                    return false;
                cryptoServiceProvider1.IV = buffer;
                byte[] numArray2 = cryptoServiceProvider1.CreateDecryptor().TransformFinalBlock(inputBuffer2, 0, inputBuffer2.Length);
                byte[] bytes = new byte[EncryptionProvider.KeySize(numArray2.Length - 2)];
                Array.Copy((Array) numArray2, 2, (Array) bytes, 0, bytes.Length);
                int num = (int) BitConverter.ToUInt16(numArray2, 0);
                string @string = Encoding.ASCII.GetString(bytes);
                return !(@string != "SWF-11-10") || !(@string != "SWF-11-11") || (!(@string != "SWF-11-12") || !(@string != "SWF-11-13"));
                }
                catch
                {
                return false;
                }
            }
            }
            return false;
        }

        internal virtual string ValidateKey()
        {
            string key = (string) null;
            LicensingManager.InitLicenseParameters();
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\" + LicensedFile.GetFileName();
            if (File.Exists(path))
            {
            StreamReader streamReader = new StreamReader((Stream) new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
            key = streamReader.ReadLine();
            streamReader.Close();
            }
            if (key == null)
            return (string) null;
            if (!this.GetKey(key))
            return (string) null;
            else
            return key;
        }
  }
}
